<?php

namespace App\Http\Controllers\Home;

use Illuminate\Http\Request;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class BlockController extends Controller
{
   //后台首页
	public function getIndex(Request $request)
	{
		// dd($request->all());
		$bid = $request->input('bid');
		//查询版块详情
        $block = DB::table('block')->select(DB::raw('block.*,users.username,users.uid'))->leftJoin('users','block.buid','=','users.uid')->where('block.bid','=',$bid)->get()[0];
		// dd($block);
		//查询置顶帖子
        $posts = DB::table('post')->select(DB::raw('post.*,block.*,users.username'))->leftJoin('block','post.bbid','=','block.bid')->leftJoin('users','post.puid','=','users.uid')->where('post.pstaus','=','2')->where('post.bbid','=',$bid)->get();
		
        //查询普通帖子
        $p = DB::table('post')->select(DB::raw('post.*,block.*,users.username'))->leftJoin('block','post.bbid','=','block.bid')->leftJoin('users','post.puid','=','users.uid')->where('post.pstaus','=','1')->where('post.bbid','=',$bid)->paginate(10);
        //获取list
        $list = $request->all();
		//解析模版
		return view('Home.block.index',['block'=>$block,'posts'=>$posts,'list'=>$list,'p'=>$p]);
	}
}
